import { ElMessage } from "element-plus";

// Map 转为 String
export function mapToString(strMap: Map<string, string>) {
  // Map 转为 Object
  let obj = Object.create(null);
  for (let [k,v] of strMap) {
    obj[k] = v;
  }
  // Object 转为 String
  return JSON.stringify(obj);
}

// String 转为 Map
export function stringToMap(jsonStr: string) {
  // String 转为 Object
  let obj = JSON.parse(jsonStr);
  // Object 转为 Map
  let strMap = new Map();
  for (let k of Object.keys(obj)) {
    strMap.set(k, obj[k]);
  }
  return strMap;
}

// 复制
export function copy(text: string) {
  navigator.clipboard.writeText(text)
  ElMessage.success({message: '复制成功!', type: 'success' })
}
